import React, { PureComponent } from 'react'
import { Text, View, TouchableHighlight, StatusBar } from 'react-native'
import AsyncStorage from '@react-native-async-storage/async-storage';

export default class App extends PureComponent {
  componentDidMount() {
    // 添加数据
    AsyncStorage.setItem('location', 'beijing')
  }

  getLocation = async () => {
    try {
      // 获取数据
      const location = await AsyncStorage.getItem('location')
      if(location !== null) {
        alert(location)
      }
    } catch(e) {
      // error reading value
    }
  }
  
  render() {
    return (
      <View style={{flex:1, marginTop: 100, alignItems: 'center'}}>
        <StatusBar
          // backgroundColor="blue" 
          barStyle="light-content"
          animated={false} 
          hidden={false} 
        />
        <TouchableHighlight onPress={() => {
          this.getLocation()
        }} >
          <Text style={{fontSize: 30}}>点击获取数据</Text>
        </TouchableHighlight>
      </View>
    )
  }
}
